<?php
include "core/int.php";

if(empty($_POST) === false){
    $username = $_POST['username'];
    $password = $_POST['password'];
    
    if (empty($username) === true || empty($password) === true ){
        $errors[] = "You need to enter and password";
    } else if(user_exists($username) === false) {
        $errors[] = "We can't find that username.Please Register";
    } else if(user_active($username) === false){
        $errors[] = "You haven't activated your account!";
    } else {
        $login = login($username, $password);
        if ($login === false){
            $errors[] = "The username/password you enter is invalid!";
        }else {
            $_SESSION['user_id'] = $login;
            header('Location: index.php');
            exit();
        }
    }
} else {
    $errors[] = 'No data received!';
    
}
include "includes/overall/overall(header).php";
if (empty($errors) === false) {
?>
<h2> Sorry But</h2>
<?php
echo output_errors($errors);
}
include "includes/overall/overall(footer).php";
?>